<template>
  <rui-page :defines="defines">
    <div v-show="isShowGpsManageList">
      <rui-query :label-width="120" ref="searchForm" :query="queryData" :query-rows="searchFormOptions" />
      <rui-table :loading="loading" border :defineId="'loanGpsManage'" :fixedLeft="['id']" :showIndex="false" :select="false" :columns="columns" :slots="[{key:'contractNo',slot:'contractNo'}]" @loadDatas="queryData" ref-query="searchForm" ref="loanTable">
        <template slot-scope="{ row, index }" slot="contractNo">
          <a type="primary" size="small" @click="showLoanDetail(row)">{{row.contractNo}}</a>
        </template>
      </rui-table>
    </div>
    <div v-if="isShowGpsAudit">
      <gpsAudit :detailParams="detailParams" @backTo="backTo" @changeLoanDetail="changeLoanDetail" />
    </div>
  </rui-page>
</template>
<script>
import gpsAudit from '_p/afs-core-business/pages/case/approve/loan-gps-manage/loanGpsAudit'
import loanGpsManageDefine from '../defines/loan-gps-manage-define'
import { getGpsManageInfoList } from '_p/afs-core-business/api/afs-case/loan-gps-manage/loanGpsManage'

export default {
  name: 'loan-gps-manage',
  components: {
    gpsAudit,
  },
  data() {
    return {
      loading: true,
      isShowGpsManageList: true,
      isShowGpsAudit: false,
      detailParams: {},
      searchFormOptions: [
        {
          defineId: 'loanGpsManage',
          fields: ['contractNo','applyStatus','dealerName','carVin','orderNo','applyNo','gpsSupplier','createTime'],
        },
      ],
      columns: [
        'applyNo',
        'dealerName',
        'contractNo',
        'carVin',
        'remarks',
        'applyStatus',
        'gpsSupplier',
        'dealName',
        'custName',
        'orderNo',
        'createBy',
        'gpsType',
        'proof',
      ],
    }
  },
  computed: {
    defines() {
      return [
        {
          id: 'loanGpsManage',
          fields: loanGpsManageDefine,
        },
      ]
    },
  },
  methods: {
    queryData(queryData) {
      let query= {
                    pageNumber: 1,
                    pageSize: 10,
                    condition: {
                        contractNo: '',
                        applyStatus: '',
                        carVin: '',
                        orderNo:'',
                        applyNo:'',
                        gpsSupplier:'',
                        startDate: '',
                        endDate: '',
                        dealerName:''
                    }
                };
                query.condition.contractNo=queryData.condition.contractNo;
                query.condition.applyStatus=queryData.condition.applyStatus;
                query.condition.carVin=queryData.condition.carVin;
                query.condition.orderNo=queryData.condition.orderNo;
                query.condition.applyNo=queryData.condition.applyNo;
                query.condition.gpsSupplier=queryData.condition.gpsSupplier;
                query.condition.dealerName = queryData.condition.dealerName;
                console.log(queryData.condition.createTime)
                query.pageNumber=queryData.pageNumber;
                query.pageSize =queryData.pageSize;
                if(typeof queryData.condition.createTime != "undefined"){

                  if (typeof queryData.condition.createTime[0] != "undefined"&&queryData.condition.createTime[0]!=null&&queryData.condition.createTime[0]!=""&&queryData.condition.createTime[1] != "undefined"&&queryData.condition.createTime[1] !=null&&queryData.condition.createTime[1] !="") {
                      query.condition.startDate = queryData.condition.createTime[0]+" 00:00:00";
                      query.condition.endDate = queryData.condition.createTime[1]+" 23:59:59";
                  }
                }
      getGpsManageInfoList(query).then((res) => {
        if (res.code === '0000') {
          let { records, total } = res.data
          this.$refs.loanTable.updateTableData(records, total)
        }
      })
    },
    refresh() {
      this.$refs.loanTable.reloadData()
    },
    showLoanDetail(param) {
      this.detailParams.applyNo = param.applyNo
      this.detailParams.contractNo = param.contractNo
      this.detailParams.taskId = param.taskId
      this.detailParams.orderNo = param.orderNo
      this.detailParams.loanTerm = param.loanTerm
      this.detailParams.gpsFullName = param.gpsFullName
      this.detailParams.carVin = param.carVin
      this.detailParams.factoryVin =param.factoryVin
      this.isShowGpsAudit = true
      this.isShowGpsManageList = false
    },
    changeLoanDetail(data){
      let d ={
        factoryVin:data.factoryVin,

      }

      console.log(data.factoryVin)
      if(data.factoryVin!=null&&data.factoryVin!=undefined&&data.factoryVin!=''){
        this.detailParams.factoryVin=data.factoryVin
        console.log(this.detailParams.factoryVin)
      this.detailParams=Object.assign({},this.detailParams,d) 
      }

    },
    backTo() {
      this.isShowGpsManageList = true
      this.isShowGpsAudit = false
      this.refresh()
    },
  },
  mounted() {
    this.refresh()
  },
}
</script>
